
import javax.microedition.lcdui.Alert;
import javax.microedition.lcdui.AlertType;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.List;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
/**
 *
 * @author Mr Bao
 */
public class ViewImageName extends List implements Runnable, CommandListener {

    private UpAnh upAnh;
    private Command cmdBack = new Command("Back", Command.BACK, 2);
    private Command cmdDelete = new Command("Xoa", Command.SCREEN, 2);
    private Alert alert;
    private Command cmdYes;
    private Command cmdNo;

    public ViewImageName(UpAnh upAnh, String title, int indexAlbum) {
        super(title, IMPLICIT);
        this.upAnh = upAnh;
        upAnh.client.ViewImageName(indexAlbum);
        addCommand(cmdBack);
        addCommand(cmdDelete);
        setCommandListener(this);
        new Thread(this).start();
    }

    public void run() {
        while (true) {
            if (upAnh.client.listImageName.size() > 0) {
                String str = upAnh.client.listImageName.elementAt(0).toString();
                if (str.equals("ENDIMAGENAME")) {
                    upAnh.client.listImageName = null;
                    break;
                } else {
                    append(str, null);
                    upAnh.client.listImageName.removeElementAt(0);
                }
            }
        }
    }

    public void commandAction(Command c, Displayable d) {
        if (c == cmdBack) {
            upAnh.DisplayViewAlbumBack();
        } else if (c == SELECT_COMMAND) {
            upAnh.DisplayImageView(getSelectedIndex(), getString(getSelectedIndex()));
        } else if (c == cmdDelete) {
             alert = new Alert("UpAnh");
            alert.setType(AlertType.INFO);
            alert.setString("Ban co muon xoa anh nay khong?");
            cmdYes = new Command("Co", Command.OK, 2);
            cmdNo = new Command("Khong", Command.BACK, 2);
            alert.addCommand(cmdYes);
            alert.addCommand(cmdNo);
            alert.setCommandListener(this);
            upAnh.display.setCurrent(alert);            
        }else if (c == cmdYes){
            upAnh.display.setCurrent(this);
            upAnh.client.DeleteImage(getSelectedIndex());
            delete(getSelectedIndex());
        }else{
             upAnh.display.setCurrent(this);
        }
    }
}
